<?php

namespace app\crontab\controller;

use \app\common\helpers\RedisUtils;
use fast\Date;

/**
 * 每天定时任务
 * @package app\crontab\controller
 */
class EveryDay extends BaseCrontab
{

    public $lockPrefix;

    public function _initialize()
    {
        parent::_initialize();
        $this->lockPrefix = date('Ymd', $this->time) . ":crontab:day:";
    }

    /**
     * 分布式锁
     * @param $key
     * @return bool
     */
    public function lock($key): bool
    {
        return RedisUtils::lock($this->lockPrefix . $key, Date::DAY);
    }

    /**
     * 每天定时运行
     * php public/index.php /crontab/EveryDay
     */
    public function index()
    {
        parent::index();
    }

    /**
     * demo
     * php public/index.php /crontab/EveryDay/demo
     * @execute true
     */
    // public function demo()
    // {
    //     if ($this->lock(__FUNCTION__)) {
    //         $this->show_msg(__FUNCTION__ . " repeat");
    //         return true;
    //     }

    //     $this->show_msg('demo end');
    // }




}
